<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <!-- 更新CDN链接 -->
<script src="https://cdn.jsdelivr.net/npm/openai@4.24.7/+esm"></script>

<!-- 使用官方ESM CDN -->
<script type="module">
    import OpenAI from "https://esm.sh/openai@4.24.7";  // 明确指定版本
  
    const openai = new OpenAI({
      apiKey: "sk-your-key",
      dangerouslyAllowBrowser: true  // 强制允许浏览器环境
    });
  
    // 示例调用
    async function main() {
      try {
        const completion = await openai.chat.completions.create({
          model: "gpt-3.5-turbo",
          messages: [{ role: "user", content: "Hello" }],
        });
        console.log(completion.choices[0].message.content);
      } catch (error) {
        console.error("API Error:", error);
      }
    }
    main();
  </script>
  
  const openai = new OpenAIApi(configuration);
</script>
</body>
</html>